/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlainPlayerParametersComponent.java
 *
 * Created on 4/Dez/2011, 18:24:14
 */

package intopo.evogame.partnerselection.tools.config;

import intopo.evogame.partnerselection.player.AbstractPlayer;
import java.awt.Color;

/**
 * The GUI component to edit the parameters used by all instances of {@code AbstractPlayer}.  This class is the root of all players.
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 4/Dez/2011
 *
 * @see intopo.evogame.partnerselection.player.AbstractPlayer
 */
public class AbstractPlayerParametersComponent
	extends javax.swing.JPanel
{

	/** Creates new form PlainPlayerParametersComponent */
	public AbstractPlayerParametersComponent ()
	{
		initComponents();
	}
	/**
	 * Update the components after a configuration file has been read.
	 */
	void updateComponents ()
	{
		this.distinctCombinationsCheckBox.setSelected (AbstractPlayer.Parameters.distinctCombinations);
		this.energyReproductionFormattedTextField.setValue (new Float (AbstractPlayer.Parameters.energyReproduction));
		this.setCandidatePartnersCapacityFormattedTextField.setValue (new Integer (AbstractPlayer.Parameters.setCandidatePartnersCapacity));
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {
      java.awt.GridBagConstraints gridBagConstraints;

      distinctCombinationsCheckBox = new javax.swing.JCheckBox();
      javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
      energyReproductionFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
      setCandidatePartnersCapacityFormattedTextField = new javax.swing.JFormattedTextField();

      setBorder(javax.swing.BorderFactory.createTitledBorder("abstract player"));
      setLayout(new java.awt.GridBagLayout());

      distinctCombinationsCheckBox.setSelected(AbstractPlayer.Parameters.distinctCombinations);
      distinctCombinationsCheckBox.setText("distinct combinations");
      distinctCombinationsCheckBox.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            distinctCombinationsCheckBoxActionPerformed(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridwidth = 2;
      add(distinctCombinationsCheckBox, gridBagConstraints);

      jLabel1.setText("reproduction energy: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      add(jLabel1, gridBagConstraints);

      energyReproductionFormattedTextField.setColumns(5);
      energyReproductionFormattedTextField.setValue(new Float (AbstractPlayer.Parameters.energyReproduction));
      energyReproductionFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            energyReproductionFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      add(energyReproductionFormattedTextField, gridBagConstraints);

      jLabel2.setText("initial capacity of partners set: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      add(jLabel2, gridBagConstraints);

      setCandidatePartnersCapacityFormattedTextField.setColumns(5);
      setCandidatePartnersCapacityFormattedTextField.setValue(new Integer (AbstractPlayer.Parameters.setCandidatePartnersCapacity));
      setCandidatePartnersCapacityFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            setCandidatePartnersCapacityFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      add(setCandidatePartnersCapacityFormattedTextField, gridBagConstraints);
   }// </editor-fold>//GEN-END:initComponents

	 private void distinctCombinationsCheckBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_distinctCombinationsCheckBoxActionPerformed
		AbstractPlayer.Parameters.distinctCombinations = this.distinctCombinationsCheckBox.isSelected ();
}//GEN-LAST:event_distinctCombinationsCheckBoxActionPerformed

	 private void energyReproductionFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_energyReproductionFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			float newValue = (Float) this.energyReproductionFormattedTextField.getValue ();
			if (newValue <= 0) {
				this.energyReproductionFormattedTextField.setBackground (Color.RED);
			}
			else {
				AbstractPlayer.Parameters.energyReproduction = newValue;
				this.energyReproductionFormattedTextField.setBackground (null);
			}
		}
	 }//GEN-LAST:event_energyReproductionFormattedTextFieldPropertyChange

	 private void setCandidatePartnersCapacityFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_setCandidatePartnersCapacityFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			int newValue = (Integer) this.setCandidatePartnersCapacityFormattedTextField.getValue ();
			if (newValue <= 0) {
				this.energyReproductionFormattedTextField.setBackground (Color.RED);
			}
			else {
				AbstractPlayer.Parameters.setCandidatePartnersCapacity = newValue;
				this.energyReproductionFormattedTextField.setBackground (null);
			}
		}
}//GEN-LAST:event_setCandidatePartnersCapacityFormattedTextFieldPropertyChange


   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JCheckBox distinctCombinationsCheckBox;
   private javax.swing.JFormattedTextField energyReproductionFormattedTextField;
   private javax.swing.JFormattedTextField setCandidatePartnersCapacityFormattedTextField;
   // End of variables declaration//GEN-END:variables

}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
